#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=2e5+1000;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
LL q[maxn],num[maxn];
LL a1[maxn],a2[maxn],b1[maxn],b2[maxn];
map<LL,LL>map1;
LL n,m;
LL solve(LL a[],LL b[],LL n,LL m){
    map1.clear();
    LL x=0;LL maxv=-1e18;
    for(LL i=1;i<=n;i++){
        map1[a[i]]++;
    }
    for(LL i=1;i<=m;i++){
        if(map1[b[i]]) x++;
    }
    maxv=max(maxv,x);
    for(LL i=1;i<=m;i++){
        if(map1[b[i]]){
            x--;
        }
        LL p1=upper_bound(a+1,a+1+n,b[i])-a-1;
        LL pos2=lower_bound(b+1,b+1+m,b[i]-p1+1)-b;

        maxv=max(maxv,x+i-pos2+1);
    }
    return maxv;
}
int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  LL t;cin>>t;
  while(t--){
    cin>>n>>m;
    LL atot1=0;LL atot2=0;LL btot1=0;LL btot2=0;
    for(LL i=1;i<=n;i++) cin>>num[i];
    for(LL i=1;i<=n;i++){
        if(num[i]>0) a1[++atot1]=num[i];
    }
    for(LL i=n;i>=1;i--){
        if(num[i]<0) a2[++atot2]=-1*num[i];
    }
    for(LL i=1;i<=m;i++) cin>>num[i];
    for(LL i=1;i<=m;i++){
        if(num[i]>0) b1[++btot1]=num[i];
    }
    for(LL i=m;i>=1;i--){
        if(num[i]<0) b2[++btot2]=-1*num[i];
    }
    LL ans1=solve(a1,b1,atot1,btot1);
    LL ans2=solve(a2,b2,atot2,btot2);
    cout<<ans1+ans2<<"\n";
  }
return 0;
}
